import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr

def sendMails(name, title, center, emailArr):
    # 设置服务器所需信息
    mail_host = 'smtp.qq.com'
    # 登录账号
    mail_user = '382177311@qq.com'
    # 密码(部分邮箱为授权码)
    mail_pass = 'zrgntwzsuhpcbhfg'
    # 邮件接受方邮箱地址
    receivers = emailArr
    # 设置email信息
    # 邮件内容设置
    message = MIMEText(center, 'plain', 'utf-8')
    # 邮件主题
    message['Subject'] = title
    # 发送方信息
    message['From'] = formataddr(pair=(name, mail_user))
    # 接受方信息
    message['To'] = receivers[0]
    # 登录并发送邮件
    try:
        # 连接到服务器
        smtpObj = smtplib.SMTP_SSL(mail_host, 465)
        # 登录到服务器
        smtpObj.login(mail_user, mail_pass)
        # 发送
        smtpObj.sendmail(
            mail_user, receivers, message.as_string())
        # 退出
        smtpObj.quit()
        print("\033[1;32m发送成功\033[0m")
    except smtplib.SMTPException as e:
        print("\033[1;31m发送失败\033[0m", e)


